<?php
namespace V1\Model;
/**
 * Description of newPHPClass
 *
 * @property   $name Description
 * 
 * @author wangzhenxian
 * @package application.components 
 */
use Think\Model;
class UserExperienceLogModel extends Model {
    
  
      /* 模型自动完成 */
    protected $_auto = array(
            array('period', 'getPeriod', self::MODEL_BOTH, 'function'),
            array('create_time', NOW_TIME),
            array('status', '1'),
        );
      
    public function log($data){
        if($this->create($data)){
                $uid = $this->add();
                if(strcmp($data['cash_flow'], 'income') == 0){
                    M('User')->where("id={$data['user_id']}")->setInc('experience',$data['experience']);
                }else if(strcmp($data['cash_flow'], 'pay') == 0){
                    M('User')->where("id={$data['user_id']}")->setDec('experience',$data['experience']);
                }
                return $uid ? $uid : -1; //0-未知错误，大于0-注册成功
        } else {
                return 0; //错误详情见自动验证注释
        } 
    }
  
}
